package com.example.fishdriver.recyclerviewdemo.updatastyle;

import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.fishdriver.recyclerviewdemo.R;
import com.example.fishdriver.recyclerviewdemo.TestAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 自定义下拉加载的样式
 */
public class UpdateStyleActivity extends AppCompatActivity {
    private RecyclerView mRecyclerView;
    private List<String> list;
    private SwipeRefreshLayout mSf;
    private Handler mHandler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_update_style);

        list = new ArrayList<>();
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        mRecyclerView = (RecyclerView) findViewById(R.id.rv);
        mSf = (SwipeRefreshLayout) findViewById(R.id.sw);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setAdapter(new TestAdapter(this, R.layout.item_de, list));
//        mSf.setRefreshing(false);
//        CustomProgressDrawable draw=new CustomProgressDrawable(this,mSf);
//        draw.setmBitmap(BitmapFactory.decodeResource(getResources(),R.mipmap.moments_refresh_icon));
//        mSf.setProgressView(draw);
        mSf.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mHandler.sendEmptyMessageDelayed(0x123, 3000);
            }
        });
        mHandler = new Handler(new MyHandler());
    }

    private class MyHandler implements Handler.Callback {

        @Override
        public boolean handleMessage(Message message) {
            mSf.setRefreshing(false);
            return false;
        }
    }
}
